package cn.j0n4than.api.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class MailUtil {

    @Autowired
    JavaMailSender sender;

    public void send(String subject, String to, String from, String content) {
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        simpleMailMessage.setSubject(subject);
        simpleMailMessage.setFrom(from);
        simpleMailMessage.setTo(to);
        simpleMailMessage.setSentDate(new Date());
        simpleMailMessage.setText(content);
        sender.send(simpleMailMessage);
    }
}
